// 测试用例
function testPlayerManagement() {
    console.log('测试选手管理功能...');
    const playerManager = new PlayerManager();
    
    // 测试添加选手
    playerManager.addPlayer('张三', '10');
    playerManager.addPlayer('李四', '8');
    
    const players = playerManager.getAllPlayers();
    console.assert(players.length === 2, '选手添加失败');
    console.assert(players[0].name === '张三', '选手姓名错误');
    console.assert(players[0].score === 10, '选手初始分数错误');
}

function testGameManagement() {
    console.log('测试比赛管理功能...');
    const gameManager = new GameManager();
    const playerManager = new PlayerManager();
    
    // 添加测试选手
    playerManager.addPlayer('王五', '10');
    playerManager.addPlayer('赵六', '8');
    
    // 模拟比赛记录
    const players = playerManager.getAllPlayers();
    const game = {
        id: Date.now().toString(),
        date: new Date().toISOString().split('T')[0],
        playerA: players[0],
        playerB: players[1],
        winner: players[0].id
    };
    
    gameManager.games.push(game);
    gameManager.saveGames();
    gameManager.updateGameList();
    
    // 验证比赛记录
    const games = gameManager.games;
    console.assert(games.length === 1, '比赛记录添加失败');
    console.assert(games[0].winner === players[0].id, '胜者记录错误');
}

// 运行测试
window.onload = function() {
    testPlayerManagement();
    testGameManagement();
    console.log('测试完成');
}